//
//  UIButton+BVideoCache.m
//  iphoneLive⁩
//
//  Created by on 2019/10/14.
//  Copyright © 2019 _ios. All rights reserved.
//

#import "UIButton+BVideoCache.h"
#import "UIImage+BVideoCache.h"

@implementation UIButton (BVideoCache)


+ (instancetype)buttonWithConfig:(BButtonConfig)config{
    return [self buttonWithConfig:config
                            frame:CGRectZero];
}

+ (instancetype)buttonWithConfig:(BButtonConfig)config
                           frame:(CGRect)frame
{
    UIButton *btn             = [[UIButton alloc] init];
    btn.frame                 = frame;
    btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    if(!IS_NULL_STR(config.nStr)){
        [btn setTitle:config.nStr forState:UIControlStateNormal];
    }
    if(!IS_NULL_STR(config.sStr)){
        [btn setTitle:config.sStr forState:UIControlStateSelected];
    }
    if(config.titleFont){
        btn.titleLabel.font = config.titleFont;
    }
    if(config.nColor){
        [btn setTitleColor:config.nColor forState:UIControlStateNormal];
    }
    if(config.sColor){
        [btn setTitleColor:config.sColor forState:UIControlStateSelected];
    }
    if(!IS_NULL_STR(config.nImgStr)){
        [btn setImage:[UIImage cImageWithName:config.nImgStr] forState:UIControlStateNormal];
    }
    if(!IS_NULL_STR(config.sImgStr)){
        [btn setImage:[UIImage cImageWithName:config.sImgStr] forState:UIControlStateSelected];
    }
    if(config.target && config.selector && [config.target respondsToSelector:config.selector]){
        [btn addTarget:config.target action:config.selector forControlEvents:UIControlEventTouchUpInside];
    }
    return btn;
}

@end
